import { Window_Selectable } from "@/windows/Window_Selectable.js";

export class Window_MenuStatus extends Window_Selectable {
    constructor(width,height) {
        super(width,height);
        this.okHandler=null;
        this.cancelHandler=null;
    }

    activate(){
        super.activate();
        this.cursorSprite.activate();
    }

    deactivate(){
        super.deactivate();
        this.cursorSprite.deactivate();
    }

    row(){return this.length();}
    viewRow(){return Math.floor(this.width/this.itemHeight());}
    itemHeight() {return (this.height - this.padding * 2)>>2;}
    length(){return $gameParty.size();}

    drawItem(index,x,y,width,height) {
        let actor = $gameParty.members()[index];
        this.changePaintOpacity(actor.isBattleMember());
        let faceSize=height<144?height:144;
        this.drawActorFace(actor, x, y, faceSize,faceSize);
        this.changePaintOpacity(true);
        this.drawActorSimpleStatus(actor, x+150, y+height/2-48, width-150);
    }

    itemEnabled(index){
        if (this._formationMode) {
            let actor = $gameParty.members()[index];
            return actor?.isFormationChangeOk();
        }
        return true;
    }

    setHandler(name,callback){
        if(name=='ok'){
            this.okHandler=callback;
        }else if(name=='cancel'){
            this.cancelHandler=callback;
        }
    }

    onResponse(index){
        this.okHandler?.($gameParty.members()[index],index);
    }

    onCancel(){
        this.cancelHandler?.();
    }
}